<template>
  <div>
    <el-container v-if="xiangqingshow === 'list'">
      <el-header>
        <h1 class="title">设备登记</h1>
        <!-- 添加新设备 -->
        <add-new></add-new>
        <div class="sh">
          <p>未审核</p>
          <p>已审核</p>
        </div>
      </el-header>
      <el-container>
        <AsideView> </AsideView>
        <MainView :datass="datas" :getnumbers="getnumbers" :getpages="getpages">
          <el-table-column slot="caozuo" prop="zip" label="操作" width="220">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
              <el-button
                type="primary"
                size="small"
                v-if="scope.row.status === 'STATUS1'"
                @click="bianji(scope.row)"
                >编辑</el-button
              >
              <el-button
                type="primary"
                size="small"
                v-else
                @click="ruku(scope.row)"
                >入库</el-button
              >

              <el-button
                type="primary"
                @click="shenhe(scope.row)"
                size="small"
                v-if="scope.row.status === 'STATUS1'"
                >审核</el-button
              >
            </template>
          </el-table-column>
        </MainView>
      </el-container>
    </el-container>
    <xiang-qing
      v-else-if="xiangqingshow === 'xiangqing'"
      :xiangqing="xiangqing"
      :names="name"
    ></xiang-qing>
    <bian-ji v-else :bianji="bianjis"></bian-ji>
  </div>
</template>

<script>
import mixins from "../../mixin";
import AsideView from "../../components/AsideView.vue";
import MainView from "../../components/MainView.vue";
import AddNew from "./components/AddNew.vue";
import XiangQing from "../../components/XiangQing.vue";
import BianJi from "./components/BianJi.vue";
export default {
  mixins: [mixins],

  components: { AsideView, MainView, AddNew, XiangQing, BianJi },
  name: "DengJi",
  data() {
    return {
      name: "设备登记详情",
      xiangqingshow: "list",
      xiangqing: {},
      bianjis: {},

      datas: {},
      // pageNo: "1",
      // pageSize: "5",
      todata: {
        pageNo: "1",
        pageSize: "15",
        id: "",
        name: "",
        status: "",
        category: "",
      },
    };
  },
  methods: {
    //跳转详情
    handleClick(row) {
      console.log(row);
      this.xiangqingshow = "xiangqing";
      this.xiangqing = row;
    },
    // 点击编辑
    bianji(row) {
      console.log("bianji ");
      this.xiangqingshow = "bianji";
      this.bianjis = row;
    },
    // 隐藏详情，显示列表、
    showlist() {
      this.$bus.$on("fhlb", (res) => {
        this.xiangqingshow = "list";
        if (res) {
          this.list();
        }
      });
    },
    // 数据请求
    // async list() {
    //   let res = await this.$axios({
    //     method: "post",
    //     url: "/pre-list",
    //     data: this.todata,
    //   });

    //   this.datas = res.data.data;
    // },
    // 数据审核
    shenhe(row) {
      console.log(row);
      this.$confirm("此操作将审核该文件, 是否继续?", "审核", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            method: "POST",
            url: "/pre-check",
            data: {
              id: row.id,
            },
          }).then((res) => {
            console.log(res);
            this.list();
          });
          this.$message({
            type: "success",
            message: "审核成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消审核",
          });
        });
    },
    // 设备入库
    ruku(row) {
      this.$confirm("此操作将入库该文件, 是否继续?", "审核", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            method: "POST",
            url: "/pre-approve",
            data: {
              id: row.id,
            },
          }).then((res) => {
            console.log(res);
            this.list();
          });
          this.$message({
            type: "success",
            message: "入库成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消审核",
          });
        });
    },
    // 数据查询
    // searchs() {
    //   this.$bus.$on("search", (data) => {
    //     console.log(data);
    //     this.todata = { ...this.todata, ...data };
    //     // console.log(this.todata);
    //     this.list();
    //   });

    //   // console.log(this.datas);
    // },
    // 查询点击分页效果
    // getnumbers(num = "15") {
    //   this.todata.pageSize = num;
    //   this.list();
    // },
    // getpages(page = "1") {
    //   this.todata.pageNo = page;
    //   this.list();
    // },
  },
  created() {
    this.$nextTick(() => {
      this.list();
      this.searchs();
      this.getpages();
      this.getnumbers();
    });
  },

  mounted() {
    this.showlist();
  },
};
</script>

<style scoped lang="less">
.el-header {
  background-color: #fff;
  color: rgb(155, 152, 152);
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  .title {
    width: 240px;
  }
  .el-button {
    flex: 1;
    text-align: left;
    font-size: 14px;
    font-weight: bold;
  }
  .sh {
    display: flex;
    font-size: 10px;
    p {
      margin-right: 20px;
      position: relative;

      &::after {
        content: "";
        display: block;
        width: 10px;
        height: 10px;
        background: red;
        position: absolute;
        top: 50% - 5px;
        right: -15px;
      }
      &:nth-child(2)::after {
        background: yellow;
      }
    }
  }
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: left;
  // line-height: 200px;
  padding-right: 5px;
  .el-input__inner {
    width: 90%;
    height: 30px;
    padding-right: 0;
    padding: 0 5px;
    .el-input__suffix {
      right: 15px;
    }
  }
}
.el-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.el-main {
  width: 100%;

  background-color: #e9eef3;
  color: #333;
  padding: 0;
}

// body > .el-container {
//   margin-bottom: 40px;
// }

.el-table .el-table__cell {
  padding: 8px 0;
}
.table_box {
  width: 100%;
  height: 85%;
}
</style>